﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Web;
using WLFramework.Data;
using WLFramework.Data.Linq;
using WLFramework.Json;

namespace SampleSite.admin.ajax.grid
{
    /// <summary>
    /// getAllAppsByRole 的摘要说明
    /// </summary>
    public class getAllAppsByRole : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int id = context.GetValueByName<int>("id");
            if (id < 0)
                throw new Exception("参数错误");

            using (CommandHelper db = new CommandHelper(CommandMethod.Read))
            {
                if (db.Context.sys_Roles.Where(k => k.R_ID == id).Count() != 1)
                    throw new Exception("恶意参数");

                var query = from p in db.Context.sys_RoleApplication
                            where p.A_State == 1 && p.R_ID == id &&
                                  p.sysRoleApplicationsysApplications.A_State == 1
                            select new
                            {
                                id = p.A_ID,
                                name = p.sysRoleApplicationsysApplications.A_CName,
                                url = p.sysRoleApplicationsysApplications.A_AppUrl,
                                description = p.sysRoleApplicationsysApplications.A_AppDescription
                            };

                context.Response.Write(JSON.Instance.ToJSON(query.ToList()));
            }
        }
    }
}